<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="__ADMIN__/__ADMIN__/static/admin/static/admin/lib/html5shiv.js"></script>
<script type="text/javascript" src="__ADMIN__/__ADMIN__/static/admin/static/admin/lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="__ADMIN__/static/admin/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="__ADMIN__/static/admin/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="__ADMIN__/static/admin/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="__ADMIN__/static/admin/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="__ADMIN__/static/admin/static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="__ADMIN__/__ADMIN__/static/admin/static/admin/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>我的桌面</title>
</head>
<body>
<div class="page-container">
<form action="" method="post" class="form form-horizontal" id="form-article-add">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>产品标题：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text"  id="goods_name" name="goods_name" value="{:$goods['goods_name']}">
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>分类栏目：</label>
			<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select id='goods_cate_id' name="goods_cate_id" class="select">
					{volist name='cates' id='vo'}
						{if $goods.goods_cate_id == $vo.id}
							<option selected="selected" value="{:$vo.id}">{:$vo.goods_cate_name}</option>
						{else /} 
							<option value="{:$vo.id}">{:$vo.goods_cate_name}</option>
						{/if}
					{/volist}
				</select>
				</span> </div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>品牌：</label>
			<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select id='brand_id' name="brand_id" class="select">
					{volist name='goods_brand' id='vo'}
						{if $goods.brand_id == $vo.id}
							<option selected="selected" value="{:$vo.id}">{:$vo.brand_name}</option>
						{else /} 
							<option value="{:$vo.id}">{:$vo.brand_name}</option>
						{/if}
					{/volist}
				</select>
				</span> </div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>权重：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text"  id="weight" name="weight" value="{:$goods['weight']}">
			</div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">产品编号：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input  id='goods_sn' type="text" class="input-text"  placeholder="如果产品编号不写那么自动生产" id="" name="goods_sn" value="{:$goods['goods_sn']}">
			</div>
		</div>
		
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">上传缩略图</label>
			<div class="formControls col-xs-8 col-sm-9 skin-minimal">
				<div class="check-box">
					<input id='uploadthumbinput'  style="float: left;" class="webuploader-pick" type="file" id="thumb_img">
					<button id='uploadthumb' style="float: left;;"> 上传</button>
					<input id='thumbsrc' style='display: none;' />
				</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">上传缩略图</label>
			<div class="formControls col-xs-8 col-sm-9 skin-minimal">
				<div class="check-box" style="float: left;">
					<img id='thumb' src="{:$goods['goods_thumb']}" style="width: 120px;height:60px"  />
				</div>
				<label style='color: green;float: left;' id='tipthumb'></label>
			</div>
		</div>		
		<script>

		</script>

		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">轮播图：</label>
			<div class="formControls col-xs-8 col-sm-9" style="position: relative;">
				<div  id='preview' style="width: 825px;height: 265px;border: 1px solid #000000;">
				<label id="clickaddpictrue" style="position: absolute ;top:100px ;left:300px;padding:10px;font-size:24px;border: 1px gray dashed;">点击添加图片</label>
					
				</div>
				<input type="file" multiple="multiple" name='imgs[]' id='multyimguploadselect' style="display: none;" />
				<button id='clearall'>清空</button>
				<button id='uploadmulty' >上传</button>
				<button id='appendpictrue' >点击继续追加</button>
				<label style='color: green;' id='tiplunbo'></label>
				<input style='display: none;' name="goods_imgs" id="goods_imgs" />
			</div>
		
		</div>		
		<script>

		</script>
		<div class="row cl" >
			
			 <div  class='bigbro'>
				<label class="form-label col-xs-4 col-sm-2">产品参数：</label>
				<label style="font-size: 14px;color: red;" id='styleadd'>[+]</label>
				<div class="formControls col-xs-8 col-sm-9" class='bigbro'>
					{volist name='goods_detail' id='vo'}
						数量<input type="text" name="goods_num[]"  placeholder="输入数量" value="{:$vo.goods_num}" class=" goods_num input-text" style=" width:20%">
						容量<input type="text" name="goods_capacity[]" placeholder="输入容量" value="{:$vo.goods_capacity}" class="goods_capacity input-text" style=" width:20%">
						适用人数<input type="text" name="people_num[]" placeholder="适用人数" value="{:$vo.people_num}" class="people_num input-text" style=" width:20%">
						<br />
						产品型号<input type="text" name="goods_model[]"  placeholder="输入型号" value="{:$vo.goods_model}" class=" goods_model input-text" style=" width:20%">
						控制方式<input type="text" name="control_model[]"  placeholder="输入控制方式" value="{:$vo.control_model}" class=" control_model input-text" style=" width:20%">
						电饭煲多功能<input type="text" name="goods_function[]"  placeholder="输入控制方式" value="{:$vo.goods_function}" class=" goods_function input-text" style=" width:20%">
						<br />
						颜色<input type="text" name="goods_color[]"  placeholder="输入控制方式" value="{:$vo.goods_color}" class=" goods_color input-text" style=" width:20%">
						加热方式<input type="text" name="heating_model[]"  placeholder="输入加热方式" value="{:$vo.heating_model}" class=" heating_model input-text" style=" width:20%">
						内胆材质<input type="text" name="goods_quality[]" placeholder="输入材质" value="{:$vo.goods_quality}" class=" goods_quality   input-text" style=" width:20%">
						<br />
						价格<input type="text" name="goods_price[]" placeholder="输入价格" value="{:$vo.goods_price}" class="goods_price   input-text" style=" width:20%">
						直径<input type="text" name="goods_diam[]" placeholder="输入直径" value="{:$vo.goods_diam}" class="goods_diam   input-text" style=" width:20%">
					{/volist}
				 </div>
			 </div>

		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">产品摘要：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea id='goods_summary' name="goods_summary" cols="" rows="" class="textarea"  value="" datatype="*10-100" dragonfly="true" nullmsg="备注不能为空！" onKeyUp="$.Huitextarealength(this,200)">{:$goods.goods_summary}</textarea>
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">详细内容：</label>
			<div class="formControls col-xs-8 col-sm-9"> 
				<script id="editor"  name='goods_desctipt' type="text/plain" style="width:100%;height:400px;">{:$goods.goods_desctipt}</script> 
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
				<input type="hidden" name="id" value="{:$id}" />
				<button id='btn' class="btn btn-primary radius" type="submit">
					<i class="Hui-iconfont">&#xe632;</i> 提交</button>
			</div>
		</div>
	</form>
</div>


<script type="text/javascript" src="__ADMIN__/static/admin/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="__ADMIN__/static/admin/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="__ADMIN__/static/admin/static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="__ADMIN__/static/admin/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="__ADMIN__/static/admin/lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="__ADMIN__/static/admin/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script>
 $(function(){
	var ue = UE.getEditor('editor');

	$('#btn').click(function(){
		var goods_name = $('#goods_name').val();
		var goods_cate_id = $('#goods_cate_id').val();
		var goods_sn = $('#goods_sn').val();
		var goods_summary = $('#goods_summary').val();
		var goods_desctipt =  ue.getContent();
		var goods_thumb = $('#thumbsrc').val();
		var goods_imgs = $('#goods_imgs').val();
		var brand_id = $('#brand_id').val();
		var id= $('input[name=id]').val();
		var weight = $('#weight').val();
		//数量
		var goods_num_arr = new Array();
		$('.goods_num').each(function(k,v){
			goods_num_arr.push($(v).val())
			console.log($(v).val())

		})		
		goods_num_arr = JSON.stringify( goods_num_arr );
		
		//容量
		var goods_capacity = $('.goods_capacity')
		var goods_capacity_arr = new Array();
		$('.goods_capacity').each(function(k,v){
			goods_capacity_arr.push($(v).val())
			
		})
		goods_capacity_arr = JSON.stringify( goods_capacity_arr );
		
		//适用人数
		var people_num = $('.people_num')
		var people_num_arr = new Array();
		$('.people_num').each(function(k,v){
			people_num_arr.push($(v).val())
			
		})
		people_num_arr = JSON.stringify( people_num_arr );
		
		//产品型号
		var goods_model = $('.goods_model')
		var goods_model_arr = new Array();
		$('.goods_model').each(function(k,v){
			goods_model_arr.push($(v).val())
			
		})
		goods_model_arr = JSON.stringify( goods_model_arr );
		
		//多功能
		var goods_function = $('.goods_function')
		var goods_function_arr = new Array();
		$('.goods_function').each(function(k,v){
			goods_function_arr.push($(v).val())
			
		})
		goods_function_arr = JSON.stringify( goods_function_arr );
		
		//颜色
		var goods_color = $('.goods_color')
		var goods_color_arr = new Array();
		$('.goods_color').each(function(k,v){
			goods_color_arr.push($(v).val())
			
		})
		goods_color_arr = JSON.stringify( goods_color_arr );
		
		//控制方式
		var control_model = $('.control_model')
		var control_model_arr = new Array();
		$('.control_model').each(function(k,v){
			control_model_arr.push($(v).val())
			
		})
		control_model_arr = JSON.stringify( control_model_arr );
		
		//加热方式
		var heating_model = $('.heating_model')
		var heating_model_arr = new Array();
		$('.heating_model').each(function(k,v){
			heating_model_arr.push($(v).val())
			
		})
		heating_model_arr = JSON.stringify( heating_model_arr );
		
		//材质
		var goods_quality = $('.goods_quality')
		var goods_quality_arr = new Array();
		$('.goods_quality').each(function(k,v){
			goods_quality_arr.push($(v).val())
			
		})
		goods_quality_arr = JSON.stringify( goods_quality_arr );
		
		//价格
		var goods_price = $('.goods_price')
		var goods_price_arr = new Array();
		$('.goods_price').each(function(k,v){
			goods_price_arr.push($(v).val())
			
		})
		goods_price_arr = JSON.stringify( goods_price_arr );
		
		//直径
		var goods_diam = $('.goods_diam')
		var goods_diam_arr = new Array();
		$('.goods_diam').each(function(k,v){
			goods_diam_arr.push($(v).val())
			
		})
		goods_diam_arr = JSON.stringify( goods_diam_arr );
		
		// console.log(goods_weight_arr)
		// return false
		$.ajax({
			type: 'POST',
			url: '{:url("admin/product/update")}',
			// async:false,
			data: {
				id:id,
				goods_name:goods_name,
				goods_cate_id:goods_cate_id,
				goods_sn:goods_sn,
				goods_summary:goods_summary,
				goods_desctipt:goods_desctipt,
				goods_thumb:goods_thumb,
				goods_imgs:goods_imgs,
				brand_id:brand_id,
				weight:weight,
				goods_num:goods_num_arr,
				goods_capacity:goods_capacity_arr,
				people_num:people_num_arr,
				goods_model:goods_model_arr,
				goods_function:goods_function_arr,
				goods_color:goods_color_arr,
				heating_model:heating_model_arr,
				control_model:control_model_arr,
				goods_quality:goods_quality_arr,
				goods_price:goods_price_arr
				},
			// dataType: 'json',
				success: function(data) {
//				console.log(data);
// 				return false;
//				 alert(data);
//				 return false;
				if(data==20000||data=='20000')
				{
						layer.msg('修改成功', {
							icon: 1,
							time: 1000
						});							
				}else
				{
						layer.msg('修改失败', {
							icon: 1,
							time: 1000
						});							
				}

			},
			error: function(data) {
				console.log(data.msg);
			},
		});
		// return false
		window.parent.location.reload();
		return false
	
	})
	
});

	window.onload = function(){ 
			$('#uploadthumbinput').change(function(){
	　　　　　　　　var objUrl = getObjectURL(this.files[0]) ;
	// 　　　　　　　　console.log("objUrl = "+objUrl) ;
	　　　　　　　　if (objUrl) {
	　　　　　　　　　　$("#thumb").attr("src", objUrl) ;
	　　　　　　　　}				
			})

		
			$('#uploadthumb').click(function(){
				 //alert(1)
				
				var  img = $('#uploadthumbinput')[0].files[0]
				var fd = new FormData();
				fd.append('goods_thumb',img)
				// console.log(img)
				$.ajax({
					type: 'POST',
					url: '{:url("admin/product/dellthumb")}',
					data: fd,
					async: false,  
					contentType: false, //不设置内容类型
					processData: false, //不处理数据
					success: function(data) {
						// console.log(data)
						$('#thumbsrc').val(data)
						layer.msg('缩略图添加成功', {
							icon: 1,
							time: 1000
						});		
						$('#tipthumb').text('已添加')
					},
					error: function(data) {
						console.log(data.msg);
					},
				});
				return false;
			})

			//多图上传
			$('#uploadmulty').click(function(){
				var goods_imgs = $('#multyimguploadselect')[0].files
				
				var fd = new FormData()
				$.each(goods_imgs, function(k, v){
				    fd.append('goods_imgs[]', v);
				});
				

				$.ajax({
					type: 'POST',
					url: '{:url("admin/product/multyimgs")}',
					data: fd,
					async: false,  
					contentType: false, //不设置内容类型
					processData: false, //不处理数据
					success: function(data) {
						 console.log(data)
						$('#goods_imgs').val(data)
						layer.msg('轮播图添加成功', {
							icon: 1,
							time: 1000
						});	
						$('#tiplunbo').text('已添加')
					},
					error: function(data) {
						console.log(data.msg);
					},
				});		
				return false
			})
			//清空
			$('#clearall').click(function(){
				$('#preview').html('')
				$('#multyimguploadselect').val('')
				return false
			})
			//多图预览
			$('#preview').click(function(){
				$('#clickaddpictrue').css('display','none')
				$('#multyimguploadselect').click()
				return false
			})
			$('#appendpictrue').click(function(){
				$('#multyimguploadselect').click()
				return false				
			})
			$('#multyimguploadselect').change(function(){
				var imgs = $(this)[0].files
				
				$(imgs).each(function(k,v){
		　　　　　　　　var objUrl = getObjectURL(v) ;
		// 　　　　　　　　console.log("objUrl = "+objUrl) ;
		　　　　　　　　if (objUrl) {
							var str = '<img  src="'+ objUrl  +'" style="width: 160px;height:90px" >'
							$('#preview').append(str)
		　　　　　　　　		
		　　　　　　　　}		
				})
// 				$(this)[0].files.each(function(k,v){
// 					console.log(v)
// 				})
// 				
			})
　　　　　　//建立一個可存取到该file的url
　　　　　　function getObjectURL(file) {
　　　　　　　　var url = null ; 
　　　　　　　　if (window.createObjectURL!=undefined) { // basic
　　　　　　　　　　url = window.createObjectURL(file) ;
　　　　　　　　} else if (window.URL!=undefined) { // mozilla(firefox)
　　　　　　　　　　url = window.URL.createObjectURL(file) ;
　　　　　　　　} else if (window.webkitURL!=undefined) { // webkit or chrome
		　　　　　　　　　　url = window.webkitURL.createObjectURL(file) ;
		　　　　　　　　}
		　　　　　　　　return url ;
		　　}
			$(document).on('click','.labelsub',function(){
				$(this).parent().remove()
			})
		$('#styleadd').click(function(){
			
			 var str='<div class="bigbro">'
				str+='	<label class="form-label col-xs-2 col-sm-2"></label>'
				str+='<div class="formControls col-xs-9 col-sm-9" >'
				str+='	数量<input type="text" name="goods_num[]"  placeholder="输入数量" value="" class="goods_num input-text" style=" width:20%">'
				str+='	容量<input type="text" name="goods_capacity[]" placeholder="输入容量" value="" class="goods_capacity input-text" style=" width:20%">'
				str+='	适用人数<input type="text" name="people_num[]" placeholder="适用人数" value="" class="people_num input-text" style=" width:20%">'					
				str+='	<br />'
				str+='	产品型号<input type="text" name="goods_model[]"  placeholder="输入型号" value="" class=" goods_model input-text" style=" width:20%">'
				str+='	控制方式<input type="text" name="control_model[]"  placeholder="输入控制方式" value="" class=" control_model input-text" style=" width:20%">'
				str+='	电饭煲多功能<input type="text" name="goods_function[]"  placeholder="输入控制方式" value="" class=" goods_function input-text" style=" width:20%">'	
				str+='	<br />'
				str+='	颜色<input type="text" name="goods_color[]"  placeholder="输入控制方式" value="" class=" goods_color input-text" style=" width:20%">'
				str+='	加热方式<input type="text" name="heating_model[]"  placeholder="输入加热方式" value="" class=" heating_model input-text" style=" width:20%">'
				str+='	内胆材质<input type="text" name="goods_quality[]" placeholder="输入材质" value="" class=" goods_quality   input-text" style=" width:20%">'
				str+='	<br />'
				str+='	价格<input type="text" name="goods_price[]" placeholder="输入价格" value="" class="goods_price   input-text" style=" width:20%">'
				str+='	直径<input type="text" name="goods_diam[]" placeholder="输入直径" value="" class="goods_diam   input-text" style=" width:20%">'
				str+=' </div>	'
				str+='  <label class="form-label col-xs-1 col-sm-1 labelsub" style="width:32px;padding-left:0px;margin-left: 0px;font-size: 14px;color: red;">[-]</label>'
				str+='</div>'
				$('.bigbro').last().after().append(str)
		})
	}
</script>
</body>
</html>